// 导航数据模型
module.exports = class Article extends require("./model") {
    /**
     * 获取导航
     */
    static getNavigation() {
        return new Promise((resolve, reject) => {
            let sql = 'SELECT * FROM webPage';
            this.query(sql).then(res => {
                resolve(res)
            }).catch(err => {
                console.log(` 获取导航失败：${err.message}`);
                reject(err)
            })
        })
    }
    /**
     * 获取指定导航
     * @param {integer} id 导航编号
     */
    static getNavigationId(id) {
        return new Promise((resolve, reject) => {
            let sql = 'SELECT * FROM webPage WHERE id = ?';
            this.query(sql, id).then(res => {
                resolve(res)
            }).catch(err => {
                console.log(` 获取导航失败：${err.message}`);
                reject(err)
            })
        })
    }
    // 是否启用导航
    static updateStatus(article) {
        return new Promise((resolve, reject) => {
            const sql =
                "UPDATE webPage SET status = ? WHERE id = ?";
            const { id, status } = article;
            this.query(sql, [status, id])
                .then((res) => {
                    resolve(res.affectedRows);
                })
                .catch((err) => {
                    console.log(`状态更新失败：${err.message}`);
                    reject(err);
                });
        });
    }
};